package com.zwb.demo.easyweb.modules.database.controller;

import com.zwb.demo.easyweb.common.entity.response.ResponseResult;
import com.zwb.demo.easyweb.modules.database.service.DatabaseLinkService;
import com.zwb.demo.easyweb.modules.database.vo.DatabaseLinkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "数据库连接接口" ,description = "数据库连接接口")
@RequestMapping("/database/link")
public class DatabaseLinkController {

    private final DatabaseLinkService databaseLinkService;

    @Autowired
    public DatabaseLinkController(DatabaseLinkService databaseLinkService) {
        this.databaseLinkService = databaseLinkService;
    }


    @GetMapping()
    @ApiOperation(value = "查询全部连接")
    public ResponseResult findAll(){
        return databaseLinkService.findAll();
    }

    @PutMapping()
    @ApiOperation(value = "新增或修改连接")
    public ResponseResult save(@RequestBody DatabaseLinkVO vo){
        return databaseLinkService.save(vo);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除连接")
    public ResponseResult delete(@PathVariable String id){
        return databaseLinkService.delete(id);
    }

    @PostMapping("/test")
    @ApiOperation(value = "测试连接")
    public ResponseResult testLink(@RequestBody  DatabaseLinkVO vo){
        return databaseLinkService.testLink(vo);
    }



}
